#!/usr/bin/python
# coding:utf-8

import sys
import json
from PyQt4 import QtGui
from functools import partial
from sql_rice.gui import engine
from sql_rice import rules
from sql_rice.tools.ricer import Ricer




def view_rice(filename, connect_to, ruledb, standalone = False):
    rules.metadata.bind = 'sqlite:///%s' % ruledb
    rules.setup_all(True)
    params = connect_to.split(';')
    params = dict(p.split('=')for p in params)
    with open(filename) as f:
        r = json.load(f)
    if standalone:
        app =QtGui.QApplication(sys.argv)
    w = engine.create_window(r, params)
    w.show()
    if standalone:
        app.exec_()


if __name__ == '__main__':
    import plac
    plac.call(partial(view_rice, standalone=True))
